package com.sh.doctors.cloud.patient.model.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.sh.doctors.cloud.patient.model.local.dao.AriticleDao
import com.sh.doctors.cloud.resp.AriticleBean

/**
 * 数据库声明
 * app_module.kt

 */
@Database(entities = arrayOf(AriticleBean::class),version = 1)
abstract class AriticleDatabase : RoomDatabase() {
    abstract fun ariticleDao(): AriticleDao

    companion object {
        @Volatile private var INSTANCE: AriticleDatabase? = null
        fun getInstance(context: Context): AriticleDatabase =
            INSTANCE ?: synchronized(this) {
                INSTANCE ?: buildDatabase(context).also { INSTANCE = it }
            }

        private fun buildDatabase(context: Context) =
            Room.databaseBuilder(context.applicationContext,
                AriticleDatabase::class.java, "app.db")
                .build()
    }
}